#ifndef RESOURCE_HPP
#define RESOURCE_HPP

#include "sdk_config.h"
#include <cstddef>
#include <string>
#include <vector>

class embedded_resource;
embedded_resource *resource_inst();
void init_module_resource(embedded_resource *inst);

struct embedded_resource_data;
class PI_API embedded_resource {
private:
    embedded_resource_data *const d;

    friend embedded_resource *resource_inst();

    embedded_resource(void(*init_fn)(embedded_resource*));
    ~embedded_resource();
public:
    bool                     register_resource(const std::string &path, const void *dat, size_t length, size_t origin_length);
    std::vector<std::string> get_file_list(const std::string &dir = {});
    std::vector<u8>          get_file_content(const std::string &path);
};

// 需要在目标中使用 DEFINE_RESOURCE_IMPL 宏去定义实现体
#define MY_RESOURCE resource_inst()

// 在任一cpp文件中添加此行，引入实现
#define DEFINE_RESOURCE_IMPL \
embedded_resource *resource_inst() { \
    static embedded_resource inst{&init_module_resource}; \
    return &inst; \
}

#endif // RESOURCE_HPP
